//
//  PXRefreshView.swift
//  PXRefesh
//
//  Created by rimi on 16/10/9.
//  Copyright © 2016年 YQ. All rights reserved.
//

import UIKit

class PXRefreshView: UIView {
    
    //定义一个枚举属性，来区别做什么事情
    //didSet 这个属性不能缩影，类似于OC里面的setter方法
    var refreshState: PXRefreshState = .nomol {
        didSet {
            switch refreshState {
            case .nomol:
                //先恢复视图状态
                arrowView.isHidden = false
                activityView.stopAnimating()
                titleL.text = "恩！再用点力"
                UIView.animate(withDuration: 0.25, animations: { 
                   self.arrowView.transform = CGAffineTransform.identity
                })
            case.pulling:
                titleL.text = "放手就刷新数据"
                UIView.animate(withDuration: 0.25, animations: { 
                    self.arrowView.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI) - 0.001)
                })
               
            case.willRefresh:
                titleL.text = "正在刷新中"
                arrowView.isHidden = true
                activityView.startAnimating()
            }
        }
    }
    
 
    @IBOutlet weak var arrowView: UIImageView!
    
    @IBOutlet weak var titleL: UILabel!

    @IBOutlet weak var activityView: UIActivityIndicatorView!
    
    class func refreshV() -> PXRefreshView {
        //获取Xib
        let xib = UINib(nibName: "PXRefreshView", bundle: nil)
        //获取视图
        return xib.instantiate(withOwner: nil, options: [:])[0] as! PXRefreshView
    }
    
    
}
